﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using Toasts.Models;

namespace Toasts.Controllers
{
    public class ToastsController : ApiController
    {
       // private Repository db = new Repository();

        // GET api/Toast
        public IEnumerable<Toast> GetToasts()
        {
            using(Repository db = new Repository()) {
                return db.Toasts.ToList();
            }
        }

        //// GET api/Toast/5
        //public Toast GetToast(int id)
        //{
        //    Toast Toast = db.Toasts.Find(id);
        //    if (Toast == null)
        //    {
        //        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
        //    }

        //    return Toast;
        //}

        //// PUT api/Toast/5
        //public HttpResponseMessage PutToast(int id, Toast Toast)
        //{
        //    if (ModelState.IsValid && id == Toast.Id)
        //    {
        //        db.Entry(Toast).State = EntityState.Modified;

        //        try
        //        {
        //            db.SaveChanges();
        //        }
        //        catch (DbUpdateConcurrencyException)
        //        {
        //            return Request.CreateResponse(HttpStatusCode.NotFound);
        //        }

        //        return Request.CreateResponse(HttpStatusCode.OK);
        //    }
        //    else
        //    {
        //        return Request.CreateResponse(HttpStatusCode.BadRequest);
        //    }
        //}

        //// POST api/Toast
        //public HttpResponseMessage PostToast(Toast Toast)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        db.Toasts.Add(Toast);
        //        db.SaveChanges();

        //        HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, Toast);
        //        response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = Toast.Id }));
        //        return response;
        //    }
        //    else
        //    {
        //        return Request.CreateResponse(HttpStatusCode.BadRequest);
        //    }
        //}

        //// DELETE api/Toast/5
        //public HttpResponseMessage DeleteToast(int id)
        //{
        //    Toast Toast = db.Toasts.Find(id);
        //    if (Toast == null)
        //    {
        //        return Request.CreateResponse(HttpStatusCode.NotFound);
        //    }

        //    db.Toasts.Remove(Toast);

        //    try
        //    {
        //        db.SaveChanges();
        //    }
        //    catch (DbUpdateConcurrencyException)
        //    {
        //        return Request.CreateResponse(HttpStatusCode.NotFound);
        //    }

        //    return Request.CreateResponse(HttpStatusCode.OK, Toast);
        //}

        //protected override void Dispose(bool disposing)
        //{
        //    db.Dispose();
        //    base.Dispose(disposing);
        //}
    }
}